package com.jdym.back.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.jdym.R;
import com.jdym.back.entity.Integral;
import com.jdym.back.service.IntegralService;
import org.apache.ibatis.annotations.Delete;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@CrossOrigin
@RequestMapping("/back/integral")
public class IntegralController {
    @Autowired
    IntegralService integralService;

    @RequestMapping("/getIntergralById/{firmId}")
    public R getIntergralById(@PathVariable int firmId){
        Integral integral=integralService.getBaseMapper().selectOne(new QueryWrapper<Integral>().eq("firm_id",firmId));
        return R.ok().data("integral",integral);
    }

//    查找出所有企业的积分
    @RequestMapping("/getIntergral")
    public R getIntergral(){
       List<Integral> list= integralService.getIntergral();
        System.out.println("企业积分："+list);
       return R.ok().data("list",list);
    }

    @PutMapping("/updateIntegradeById")
    public R updateIntegradeById(@RequestParam("inId") Integer inId,@RequestParam("InteGrate") Integer InteGrate){
        System.out.println("inId:"+inId);
        Integral integral=new Integral();
        integral.setInId(inId);
        integral.setIntegralval(InteGrate);
        integralService.getBaseMapper().updateById(integral);
        return R.ok();
    }
    @DeleteMapping(value = "/remove/{id}")
    public R remove(@PathVariable int id){
        integralService.remove(id);
        return R.ok();
    }
}
